import { useIntersectionObserver } from '@vueuse/core'
export default {
  lazyimg: {
    mounted (dom, obj) {
      const { stop } = useIntersectionObserver(
        dom,
        ([{ isIntersecting }], option) => {
          if (isIntersecting) {
            stop()
            dom.src = obj.value
          }
        },
        // 设置配制
        { threshold: 0 }
      )
    },
    updated (dom, obj) {
      if (obj.oldValue !== obj.value) {
        const { stop } = useIntersectionObserver(
          dom,
          ([{ isIntersecting }], option) => {
            if (isIntersecting) {
              stop()
              dom.src = obj.value
            }
          },
          // 设置配制
          { threshold: 0 }
        )
      }
    }
  }
}
